using System.Configuration;
using System.Diagnostics;
using Core.IocHelpers;

namespace Core.Settings
{
  ///<summary>Core (global) access to the WPF App settings</summary>
  [AutoRegister]
  public class AppSettings : IAppSettings
  {
    private static ApplicationSettingsBase InternalSource;

    #region Copy from Settings.Designer.cs

    [UserScopedSetting]
    [DebuggerNonUserCode]
    [DefaultSettingValue("0")]
    public int CommunityId
    {
      get { return ((int) (InternalSource["CommunityId"])); }
      set
      {
        var save = InternalSource["CommunityId"].AsInt() != value;
        if (save)
        {
          InternalSource["CommunityId"] = value;
          InternalSource.Save();
        }
      }
    }

    [UserScopedSetting]
    [DebuggerNonUserCode]
    [DefaultSettingValue("0")]
    public int ElectionId
    {
      get { return ((int) (InternalSource["ElectionId"])); }
      set
      {
        var save = InternalSource["ElectionId"].AsInt() != value;
        if (save)
        {
          InternalSource["ElectionId"] = value;
          InternalSource.Save();
        }
      }
    }

    [UserScopedSetting]
    [DebuggerNonUserCode]
    [DefaultSettingValue("0")]
    public int TellerId
    {
      get { return ((int) (InternalSource["TellerId"])); }
      set
      {
        var save = InternalSource["TellerId"].AsInt() != value;
        if (save)
        {
          InternalSource["TellerId"] = value;
          InternalSource.Save();
        }
      }
    }

    [UserScopedSetting]
    [DebuggerNonUserCode]
    [DefaultSettingValue("0")]
    public int LocationId
    {
      get { return ((int) (InternalSource["LocationId"])); }
      set
      {
        var save = InternalSource["LocationId"].AsInt() != value;
        if (save)
        {
          InternalSource["LocationId"] = value;
          InternalSource.Save();
        }
      }
    }

    [UserScopedSetting]
    [DebuggerNonUserCode]
    [DefaultSettingValue("0")]
    public int ComputerId
    {
      get { return ((int) (InternalSource["ComputerId"])); }
      set
      {
        var save = InternalSource["ComputerId"].AsInt() != value;
        if (save)
        {
          InternalSource["ComputerId"] = value;
          InternalSource.Save();
        }
      }
    }

    [UserScopedSetting]
    [DebuggerNonUserCode]
    [DefaultSettingValue("")]
    public string DbFilePath
    {
      get
      {
        return ((string)(InternalSource["DbFilePath"]));
      }
      set
      {
        var save = ((string)InternalSource["DbFilePath"]) != value;
        if (save)
        {
          InternalSource["DbFilePath"] = value;
          InternalSource.Save();
        }
      }
    }

    [UserScopedSetting]
    [DebuggerNonUserCode]
    [DefaultSettingValue("")]
    public string ImportXmlFilePath
    {
      get { return ((string) (InternalSource["ImportXmlFilePath"])); }
      set
      {
        var save = ((string)InternalSource["ImportXmlFilePath"]) != value;
        if (save)
        {
          InternalSource["ImportXmlFilePath"] = value;
          InternalSource.Save();
        }
      }
    }

    #endregion

    /// <summary>
    /// Copy this section, replace "this" with "InternalSource"
    /// </summary>

    #region IAppSettings Members

    public ApplicationSettingsBase Source
    {
      get { return InternalSource; }
    }

    public void LinkToSource(ApplicationSettingsBase source)
    {
      InternalSource = source;
    }

    #endregion
  }
}